/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase - T8
 * <p>Powered by webrx On 2021-12-24 15:07:25
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T8 {
    static CountDownLatch latch = new CountDownLatch(5);

    static void work() {
        String t = Thread.currentThread().getName();
        System.out.println(t + ":线程启动...");
        for (int i = 0; i < 20; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.printf("%s:item%02d%n", t, i);
        }
        System.out.println(t + ":结束");
        latch.countDown();
    }

    static void over() {
        String t = Thread.currentThread().getName();
        System.out.println(t + ":线程启动...");
        try {
            latch.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("全部结束了....");
    }


    public static void main(String[] args) {
        new Thread(T8::work, "t1").start();
        new Thread(T8::work, "t2").start();
        new Thread(T8::work, "t3").start();
        new Thread(T8::work, "t4").start();
        new Thread(T8::work, "t5").start();

        //收尾工作
        new Thread(T8::over, "over").start();


    }
}
